package org.example.plugins;

import com.baomidou.mybatisplus.extension.plugins.handler.TableNameHandler;

import java.util.Arrays;
import java.util.List;
import java.util.Objects;

public class DynamicTableNameHandler implements TableNameHandler {
    private final List<String> tableNames;

    //构造函数，构造动态表名处理器的时候，传递tableNames参数
    public DynamicTableNameHandler(String... tableNames) {
        this.tableNames = Arrays.asList(tableNames);
    }

    @Override
    public String dynamicTableName(String sql, String tableName) {
        String tableExt = OperatorHolder.getTableExt();
        if (this.tableNames.contains(tableName) && Objects.nonNull(tableExt)) {
            return tableName + tableExt;
        } else {
            return tableName;
        }
    }
}
